﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Windows.Forms;

namespace CoreLib.Utils
{
    public class RegularExpressionMatches
    {
        public static bool IsAnEmail(string text, Control control, string errorMessage)
        {
            if (!(string.IsNullOrEmpty(text)) && !(new Regex("^[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+.[A-Za-z]{2,4}$")).IsMatch(text))
            {
                control.Text = errorMessage;
                return false;
            }
            else
            {
                control.Text = "";
                return true;
            }
        }

        public static bool IsAnAmount(string text, Control control, string errorMessage)
        {
            //if (!((string.IsNullOrEmpty(text)) ?
            //    false : (new Regex("^[0-9]+(.[0-9]{1,2})?$")).IsMatch(text)))
            //{
            //    control.Text = errorMessage;
            //    return false;
            //}
            //else
            //{
            //    control.Text = "";
                return true;
            //}
        }
    }

    public class ErrorUtilities
    {
        public static bool ShowErrorMessages(bool isError, Control control, string errorMessage)
        {
            if (isError)
                control.Text = errorMessage;
            else
                control.Text = "";

            return isError;
        }
    }
}
